package com.ctgu.chatapp.view

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.NavigationUI
import com.ctgu.chatapp.R
import com.ctgu.chatapp.databinding.ActivityMainBinding
import com.ctgu.chatapp.viewModel.MainViewModel

class HomePage : BaseActivity() {

    val viewModel by lazy {
        ViewModelProvider(
            this,
            ViewModelProvider.AndroidViewModelFactory.getInstance(application)
        )[MainViewModel::class.java]
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding =
            DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.fragment_container_main_tag) as NavHostFragment
        NavigationUI.setupWithNavController(binding.bottomBar, navHostFragment.navController)
        binding.viewModel = viewModel
        binding.lifecycleOwner = this
        ActivityCollector.addActivity(this, this.javaClass)
    }
}